package com.tgy.leetcode;

public class _面试题_17_21_直方图的水量_01 {

    public static int trap(int[] height) {

        int len = height.length;
        int[] leftToRight = new int[len];
        int[] rightToLeft = new int[len];

        int water = 0;

        leftToRight[0] = height[0];

        for (int i = 1; i < len; i++) {

            leftToRight[i] = Math.max(leftToRight[i - 1],height[i]);
        }

        rightToLeft[len - 1] = height[len - 1];

        for (int i = len - 2; i >= 0 ; i--) {

            rightToLeft[i] = Math.max(rightToLeft[i + 1],height[i]);
        }




        return water;
    }

    public static void main(String[] args) {

        int[] heights = {0,1,0,2,1,0,1,3,2,1,2,1};

        System.out.println(trap(heights));
    }
}
